<template>
  <view class="modal-overlay" v-if="show" @click="handleClose">
    <view class="modal-content" @click.stop>
      <view class="modal-header">
        <text class="modal-title">选择心情</text>
        <view class="close-btn" @click="handleClose">
          <text class="close-icon">×</text>
        </view>
      </view>
      
      <view class="mood-grid">
        <view 
          class="mood-item" 
          v-for="mood in moodOptions" 
          :key="mood.name"
          :class="{ active: selected === mood.name }"
          @click="handleSelect(mood.name)"
        >
          <text class="mood-emoji">{{ mood.emoji }}</text>
          <text class="mood-name">{{ mood.name }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'MoodModal',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    selected: {
      type: String,
      default: ''
    }
  },
  emits: ['update:show', 'select'],
  data() {
    return {
      moodOptions: [
        { name: '开心', emoji: '😊' },
        { name: '平静', emoji: '😌' },
        { name: '兴奋', emoji: '🤩' },
        { name: '难过', emoji: '😢' },
        { name: '愤怒', emoji: '😠' },
        { name: '焦虑', emoji: '😰' },
        { name: '疲惫', emoji: '😴' },
        { name: '感动', emoji: '🥺' },
        { name: '满足', emoji: '😄' },
        { name: '惊讶', emoji: '😲' },
        { name: '思考', emoji: '🤔' },
        { name: '放松', emoji: '😎' }
      ]
    }
  },
  methods: {
    handleClose() {
      this.$emit('update:show', false)
    },
    
    handleSelect(mood) {
      this.$emit('select', mood)
    }
  }
}
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  width: 80%;
  max-height: 70vh;
  background-color: #ffffff;
  border-radius: 16rpx;
  padding: 32rpx;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32rpx;
  padding-bottom: 24rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.modal-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333333;
}

.close-btn {
  width: 48rpx;
  height: 48rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-icon {
  font-size: 32rpx;
  color: #999999;
}

.mood-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16rpx;
  max-height: 60vh;
  overflow-y: auto;
}

.mood-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24rpx;
  border-radius: 12rpx;
  background-color: #f8f8f8;
  border: 2rpx solid transparent;
  transition: all 0.3s;
}

.mood-item.active {
  background-color: #e6f7ff;
  border-color: #1890ff;
}

.mood-item:active {
  transform: scale(0.95);
}

.mood-emoji {
  font-size: 40rpx;
  margin-bottom: 8rpx;
}

.mood-name {
  font-size: 26rpx;
  color: #333333;
}
</style> 